import java.io.FileWriter;
import java.io.IOException;

/**
 * General class containing main program to run the
 * iterated Prisoner's Dilemma (IPD).
 * @author	081028AW
 */
public class RunIPD extends Object
   {
  /**
   * Main program to start IPD program.
 * @throws IOException 
   */

   public static void main(String args[]) throws IOException
      {
      int i;
      
      
      int maxSteps = 100;

      Strategy player1, player2;
      IteratedPD ipd;

      for (i=0; i<args.length; i++)
         {
        /* check parameters */
         if (args[i].equals("-l") || args[i].equals("-L"))
            {
            maxSteps = Integer.parseInt(args[i+1]);
            System.out.println(" Max steps = " + maxSteps);
            }  /* if */
         }  /* for i */

      int[] aPlayAll = new int[100];
      int[] aRandom = new int[100];
      int[] aKnown = new int[100];
      
      for (i=0; i <100; i++)
      {
    	  maxSteps = i+1;
	      int playAll = 0;
	      int random =0;
	      int known = 0;
	      
	      player1 = new StrategyHRTPlayAll();
	      player2 = new StrategyHRTRandomK();
	      
	      ipd = new IteratedPD(player1, player2);
	
	      ipd.runSteps(maxSteps);
	
	      playAll += ipd.player1Score();
	      random += ipd.player2Score();
	      
	      System.out.printf(" Play All score = %d\n", ipd.player1Score());
	      System.out.printf(" Random score = %d\n\n", ipd.player2Score());
	
	      player1 = new StrategyHRTPlayAll();
	      player2 = new StrategyHRTKnown();
	      
	      ipd = new IteratedPD(player1, player2);
	
	      ipd.runSteps(maxSteps);
	
	      playAll += ipd.player1Score();
	      known += ipd.player2Score();
	      
	      System.out.printf(" Play All score = %d\n", ipd.player1Score());
	      System.out.printf(" Known score = %d\n\n", ipd.player2Score());
	
	      player1 = new StrategyHRTRandomK();
	      player2 = new StrategyHRTKnown();
	      
	      ipd = new IteratedPD(player1, player2);
	
	      ipd.runSteps(maxSteps);
	
	      random += ipd.player1Score();
	      known += ipd.player2Score();
	      
	      System.out.printf(" Random score = %d\n", ipd.player1Score());
	      System.out.printf(" Known score = %d\n\n", ipd.player2Score());
	
	      System.out.printf(" Play All total score = %d\n", playAll);
	      System.out.printf(" Random total score = %d\n", random);
	      System.out.printf(" Known total score = %d\n", known);
	      
	      aPlayAll[i] = playAll;
	      aRandom[i] = random;
	      aKnown[i] = known;
      }
  	  String sFileName = "ThreeWayScore.txt";
	  FileWriter scoreOutput = new FileWriter(sFileName);
	  
	  scoreOutput.write("1");
      for (i=0; i<100; i++){
    	  scoreOutput.write("," + aPlayAll[i]);
      }
      scoreOutput.write("\n");
	  scoreOutput.write("2");
      for (i=0; i<100; i++){
    	  scoreOutput.write("," + aRandom[i]);
      }
      scoreOutput.write("\n");
	  scoreOutput.write("3");
      for (i=0; i<100; i++){
    	  scoreOutput.write("," + aKnown[i]);
      }
      scoreOutput.write("\n");
      scoreOutput.close();
      
      }  /* main */
   }  /* class RunIPD */

